package com.j2110.service;

import com.j2110.dao.UserDao;
import com.j2110.pojo.User;
import com.j2110.utils.Md5Utils;
import com.j2110.utils.Result;

public class UserService {
    private UserDao dao = new UserDao();

    public Result login(User u) {
        User user = dao.queryByUsername(u.getUsername());
        //加密用户输入的密码
        String pwd = Md5Utils.MD5Encode(u.getPassword(), "utf-8", false);
        if (user != null){
            if (pwd.equals(user.getPassword())){
                //保证用户的密码安全
                user.setPassword(null);
                return Result.me(user);
            }else {
                return Result.me(false).setMsg("用户名或密码错误");
            }
        }else {
            return Result.me(false).setMsg("用户名或密码错误");
        }
    }
}
